(function() {
// Store URL configuration - not directly used with Mintegral SDK
// as they handle the store redirect via window.install()
const IOS_STORE_URL = "https://apps.apple.com/us/app/farkle-dice-roll/id6476893083";
const ANDROID_STORE_URL = "https://play.google.com/store/apps/details?id=com.funcraft.farkle&hl=en";
// Game state variables
let gameInitialized = false;
let gameLoaded = false;
// Initialize the game when document is ready
function initializeGame() {
console.log("Initializing game");
// Setup game assets, initialize game logic, etc.
preloadGameAssets(function() {
gameLoaded = true;
// Call gameReady when all resources are loaded
if (window.gameReady) {
console.log("Calling gameReady");
window.gameReady();
}
});
// Set up download button click handlers
setupDownloadButtons();
}
// Setup all download buttons in the game
function setupDownloadButtons() {
// Find all download buttons
const downloadButtons = document.querySelectorAll('.download-btn');
// Add click event listeners to all download buttons
downloadButtons.forEach(function(button) {
button.addEventListener('click', function(e) {
console.log("Download button clicked");
// Call the required Mintegral install method
if (window.install) {
console.log("Calling window.install");
window.install();
}
});
});
}
// IMPORTANT: Remove the openStore function as it's not compliant with Mintegral
// Instead, we'll redirect all calls to the correct window.install method
window.openStore = function() {
console.log("openStore called - redirecting to window.install");
if (window.install) {
window.endGame();
window.install();
} else {
console.log("window.install not available");
}
};
// Preload game assets (simulation)
function preloadGameAssets(callback) {
console.log("Preloading game assets");
// Simulate asset loading time
setTimeout(function() {
console.log("Assets loaded");
callback();
}, 1000);
}
// We'll keep this for your game logic, but make sure to call window.gameEnd also
window.endGame = function(didWin) {
console.log("endGame called - now calling window.gameEnd");
//showGameEndUI(didWin);
// Call the required Mintegral gameEnd method
if (window.gameEnd) {
console.log("Calling window.gameEnd");
window.gameEnd();
}
};
// Show game end UI
function showGameEndUI(didWin) {
// Implementation would depend on your game's UI system
console.log("Showing game end UI");
// Make sure download button is prominent with animation/effects
// as required by point #11 in the documentation
}
// Called when player wants to retry the game
window.retryGame = function() {
console.log("Retrying game");
// Reset game state
resetGameState();
// Call the required Mintegral gameRetry method
if (window.gameRetry) {
console.log("Calling window.gameRetry");
window.gameRetry();
}
};
// Reset game state for retry
function resetGameState() {
// Implementation would depend on your game's state management
console.log("Resetting game state");
}
// Required gameStart function that will be called by Mintegral SDK
window.gameStart = function() {
console.log("Game starting (called by Mintegral SDK)");
// Start your game logic, animations, countdown, background music, etc.
startGameLogic();
};
// Start actual game logic
function startGameLogic() {
// Implementation would depend on your game
console.log("Starting game logic");
// Example: start countdown, animations, etc.
}
// Required gameClose function that will be called by Mintegral SDK
window.gameClose = function() {
console.log("Game closing (called by Mintegral SDK)");
// Clean up resources, stop sounds, animations, etc.
stopBackgroundMusic();
cleanupResources();
};
// Stop background music
function stopBackgroundMusic() {
// Implementation would depend on your audio system
console.log("Stopping background music");
}
// Clean up any resources
function cleanupResources() {
// Implementation would depend on your resource management
console.log("Cleaning up resources");
}
// Optional: Report custom events using Mintegral's tracking API
window.reportCustomEvent = function(actionNumber) {
// Ensure action number is between 1-5 as per documentation
if (actionNumber >= 1 && actionNumber <= 5) {
console.log("Reporting custom event:", actionNumber);
if (window.HttpAPI && window.HttpAPI.sendPoint) {
window.HttpAPI.sendPoint("action&action=" + actionNumber);
}
}
};
// Initialize when document is ready
if (document.readyState === "complete" || document.readyState === "interactive") {
setTimeout(initializeGame, 1);
} else {
document.addEventListener("DOMContentLoaded", initializeGame);
}
})();